
package com.dy.net;
/**
 * @Description:
 * @Date：2018年6月28日
 * @author： DongY
 * @version ：1.0
 * 	  1.[2018年6月28日]CreatBy：dy
 */

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.dy.config.MysqlConfig;

public class DoConnection {
	private static Connection connection;

	public static Connection getConnection(final MysqlConfig config) throws ClassNotFoundException, SQLException {
		if (connection == null) {
			synchronized (DoConnection.class) {
				if (connection == null) {
					Class.forName(config.getDriver());
					connection = DriverManager.getConnection(config.getUrl(), config.getUser(), config.getPassword());
				}
			}
		}
		return connection;
	}

	public static void closeConnection(final Connection c) throws SQLException {
		c.close();
	}
}
